#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

#####################
#PUPPETEER RECIPE
#####################
# Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others)
# Note: this installs the necessary libs to make the bundled version of Chromium that Puppeteer
# installs, work.

#http://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${CHROME_VERSION}_amd64.deb
#http://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${CHROME_VERSION}_amd64.deb


# 替换为国内镜像源（阿里云归档源）
RUN echo "deb http://mirrors.aliyun.com/debian-archive/debian buster main contrib non-free" > /etc/apt/sources.list && \
    echo "deb http://mirrors.aliyun.com/debian-archive/debian-security buster/updates main contrib non-free" >> /etc/apt/sources.list && \
    echo "deb http://mirrors.aliyun.com/debian-archive/debian buster-updates main contrib non-free" >> /etc/apt/sources.list && \
    # 跳过有效期检查（归档源可能过期）
    echo "Acquire::Check-Valid-Until \"false\";" > /etc/apt/apt.conf.d/10-nocheckvalid

#https://mirrors.aliyun.com/armbian/pool/bookworm-desktop/g/google-chrome-stable/google-chrome-stable_135.0.7049.114-1_amd64.deb
ARG CHROME_VERSION="135.0.7049.114-1"
RUN apt-get update && apt-get -f install && apt-get -y install apt-utils wget gnupg2 
RUN apt-get -f install && apt-get -y install gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils
RUN wget --no-verbose -O /tmp/chrome.deb https://mirrors.aliyun.com/armbian/pool/bookworm-desktop/g/google-chrome-stable/google-chrome-stable_${CHROME_VERSION}_amd64.deb \
&& apt-get update \
&& apt-get install -y /tmp/chrome.deb --no-install-recommends --allow-downgrades \
&& rm /tmp/chrome.deb


ENV PUPPETEER_EXECUTABLE_PATH "/usr/bin/google-chrome-stable"

# NOTE: REMOVED THIS WHILST DEBUGGING - D
# Add user, so we don't need --no-sandbox.
# same layer as npm install to keep re-chowned files from using up several hundred MBs more space    
#RUN groupadd -r pptruser && useradd -r -g pptruser -G audio,video pptruser \
    #&& mkdir -p /home/pptruser/Downloads \
    #&& chown -R pptruser:pptruser /home/pptruser
#
## Run everything after as non-privileged user.
#
#USER pptruser

#ENV PUPPETEER_EXECUTABLE_PATH "/usr/bin/google-chrome-unstable"

#####################
#END PUPPETEER RECIPE
#####################

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY Util.Setvices/Util.Setvices.csproj Util.Setvices/
RUN dotnet restore "Util.Setvices/Util.Setvices.csproj"
COPY . .
WORKDIR "/src/Util.Setvices"
RUN dotnet build "Util.Setvices.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Util.Setvices.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Util.Setvices.dll"]
